home *** CD-ROM | disk | FTP | other *** search
/ Nebula 2 / Nebula Two.iso / SourceCode / Tutorial / Stepstone_Tutorial / Fruit.m < prev    next >
Text File  |  1995-06-12  |  980b  |  50 lines

  1. /* Objective_C Implementation of the Fruit Class */
  2.  
  3. #import "Fruit.h"
  4.  
  5. @implementation Fruit : Object
  6. {
  7.     char * color;
  8.     int diameter;
  9. }
  10.  
  11. // Create a new fruit by using the superclass 'new' method
  12. + create {
  13.     id newInstance;     // local variable declaration
  14.  
  15.     newInstance = [ self new ];// create new instance
  16.     [ newInstance diameter: 1];// set the diameter
  17.     [ newInstance color: "green" ]; // set the color
  18.     return newInstance;     // return the new instance
  19. }
  20.  
  21. // Set the color instance variable fo the Fruit Object
  22. -color: (char*) aColor{
  23.     color = aColor;
  24.     return self;
  25. }
  26.  
  27. //Return the value of the color instance variable
  28. - (char*) color {
  29.     return color;
  30. }
  31.  
  32. //Set the diameter instance variable of the Fruit objects
  33. -diameter: (int) aSize {
  34.     diameter = aSize;
  35.     return self;
  36. }
  37.  
  38. //Return the value of the diameter instance variable
  39. - (int) diameter {
  40.     return diameter;
  41. }
  42.  
  43. // Tell a Fruit object to increase its diameter
  44. - grow {
  45.     diameter = diameter + 1;
  46.     return self;
  47. }
  48.  
  49. @end
  50.